<?php
/*
 * File function.display_errors.php for project Rijlesplanner.nl
 * Created on 25 apr 2008 at 21:36:22 by Ivar Pruijn
 */

/**
 * Displays the error messages it is given in a uniform manner
 * @tutorial http://www.smarty.net/manual/en/plugins.functions.php
 * @param array $errors The errors passed to this function from the Smarty template
 * @param string $heading The heading placed on top of the list of errors
 * @param string $width The width of the error box (including e.g. 'px')
 */
function smarty_function_display_errors($params, &$smarty) {
	global $logger;
	$application_errors = $_SESSION['application_errors'];
	# $logger->log("Testing",PEAR_LOG_DEBUG);
	if (!isset($params['errors']) || empty($params['errors'])) {
		$logger->log("Access plugin: missing parameter 'errors'",PEAR_LOG_WARN);
      //  $smarty->trigger_error("access plugin: missing parameter 'errors'");
    } else {
    	$errors = $params['errors'];
    	$errorListHeading = isset($params['heading']) ? $params['heading'] : "<h3 class=\"tekst\">Sorry, het volgende is niet goed gegaan:</h3>";
    	// $errorListHeading = isset($params['heading']) ? $params['heading'] : "";
    	$errorListWidth = isset($params['width']) ? $params['width'] : "auto";
    	// $errorList = '<div style="border:1px solid red; padding: 5px; width: '.$errorListWidth.'">';
    	$errorList .= $errorListHeading;
    	$errorList .= '<ul class="errors">';
    	
    	$unknown_not_seen = true;
    	
    	foreach($errors AS $error) {
    		if(array_key_exists($error['code'],$application_errors)) {
	   			$errorMessage = $application_errors[$error['code']];	
      		$errorList .= '<li>'.$errorMessage.'</li>';
	  		} else {
    			if ($unknown_not_seen) {
    				$errorMessage = "Onbekende foutcode";
    				$unknown_not_seen = false;
		    		$errorList .= '<li>'.$errorMessage.'</li>';
    			}
    		}
    	}
    	$errorList .= '</ul>';
		return $errorList;
	}
}
?>
